namespace SCIENEW {
    public class FluidConnection(FluidTransferrer fromTransferrer, FluidTransferrer toTransferrer, FluidConnector fromConnector, FluidConnector toConnector, float rate) {
        public FluidTransferrer FromTransferrer = fromTransferrer;
        public FluidTransferrer ToTransferrer = toTransferrer;
        public FluidConnector FromConnector = fromConnector;
        public FluidConnector ToConnector = toConnector;
        public float Rate = rate;

        /// <summary>
        /// 接口的模拟：从一端移除液体，接入另一端
        /// </summary>
        /// <param name="dt"></param>
        public void Simulate(float dt) {
            ITank to = ToTransferrer.GetTank();
            if (to == null) return;
            if (ToTransferrer.IsFull(to)) return;
            ITank from = FromTransferrer.GetTank();
            if (from == null) return;

            float volume = Rate * dt;
            int fluidValue = FromTransferrer.RemoveFluid(from, volume, out float removedVolume, out int removedTankIndex);
            float remainFluidVolume = ToTransferrer.AcquireFluid(to, removedVolume, fluidValue);
            from.AddTankFluid(removedTankIndex, fluidValue, remainFluidVolume, out _);
        }
    }
}